//
//  KWNDealData.m
//  KWNClient
//
//  Created by 张明磊 on 14/10/29.
//  Copyright (c) 2014年 张明磊. All rights reserved.
//

#import "KWNDealData.h"
#import "Model_questionList.h"
#import "Model_questionDetail.h"
#import "Model_lawyerReply.h"
#import "Model_lawyerInfo.h"
#import "Model_useAsked.h"
#import "Model_myComment.h"
#import "Model_myList.h"
#import "Model_user.h"

@implementation KWNDealData

+ (NSMutableArray *)deal_questListDataWithDicArray:(NSArray *)array_dic{
    NSMutableArray *array_data = [NSMutableArray arrayWithCapacity:[array_dic count]];
    for(NSDictionary *dic in array_dic)
    {
        NSString *string_id = [dic objectForKey:@"id"];
        NSString *string_mobile = [dic objectForKey:@"mobile"];
        NSString *string_count = [dic objectForKey:@"count"];
        NSString *string_text = [dic objectForKey:@"question"];
        NSString *string_time = [dic objectForKey:@"time"];
        NSString *string_are = [dic objectForKey:@"question_area"];
        NSString *string_type = [dic objectForKey:@"question_type"];
        NSArray *array_img = [dic objectForKey:@"question_img"];
        NSArray *array_img_small = [dic objectForKey:@"img_thumbnail"];
        
        Model_questionList *model_list = [[Model_questionList alloc] init];
        if(string_id && ![string_id isKindOfClass:[NSNull class]]){
            model_list.string_id = string_id;
        }
        if(string_mobile && ![string_mobile isKindOfClass:[NSNull class]]){
            model_list.string_phone = string_mobile;
        }
        if(string_count && ![string_count isKindOfClass:[NSNull class]]){
            model_list.string_count = string_count;
        }
        if(string_time && ![string_time isKindOfClass:[NSNull class]]){
            model_list.string_time = string_time;
        }
        if(string_text && ![string_text isKindOfClass:[NSNull class]]){
            model_list.string_content = string_text;
        }
        if(string_are && ![string_are isKindOfClass:[NSNull class]]){
            model_list.string_area = string_are;
        }
        if(string_type && ![string_type isKindOfClass:[NSNull class]]){
            model_list.string_kind = string_type;
        }
        if(array_img && ![array_img isKindOfClass:[NSNull class]]){
            model_list.array_img = array_img;
        }
        if(array_img_small && ![array_img_small isKindOfClass:[NSNull class]]){
            model_list.array_img_small = array_img_small;
        }
        
        //计算高度
        CGFloat height = 10 + 20 + 10 + 10 + 15 + 10;
        if (model_list.array_img.count > 0) {
            height = height + 50 + 10;
        }
        CGFloat textHeight = [UIUtils heightFor:string_text withFont:FontOfQuestionList labWidth:MainScreenWidth - 20];
        if (textHeight > 40) {
            textHeight = 40;
        }
        else
        {
            textHeight = 20;
        }
        
        height = height + textHeight;
        model_list.cgfloat_height = height;
        
        [array_data addObject:model_list];
    }
    return array_data;
}

#pragma mark - 处理问题列表数据 -
/**
 *  问题详情
 */
+ (NSMutableArray *)deal_questDetailDataWithDic:(NSDictionary *)dic{
    //用户问题
    NSString *string_uid = [[Model_user sharedInstance] getUserID];
    NSMutableArray *array_data = [NSMutableArray array];
    NSDictionary *userinfo = [dic objectForKey:@"userinfo"];
    Model_questionDetail *detail_user = [[Model_questionDetail alloc] init];
    NSString *string_adopt_replyid = [userinfo objectForKey:@"adopt_replyid"];
    if(!string_adopt_replyid || [string_adopt_replyid isKindOfClass:[NSNull class]]){
        
    }
    else{
        detail_user.string_adopt_replyid = string_adopt_replyid;
    }
    NSString *string_count = [userinfo objectForKey:@"count"];
    NSString *string_question = [userinfo objectForKey:@"question"];
    NSString *string_question_area = [userinfo objectForKey:@"question_area"];
    NSString *string_time = [userinfo objectForKey:@"time"];
    NSString *string_type = [userinfo objectForKey:@"question_type"];
    NSString *string_issolve = [userinfo objectForKey:@"is_solve"];
    NSString *string_mobile = [userinfo objectForKey:@"mobile"];
 
    detail_user.string_mobile = string_mobile;
    detail_user.string_count = string_count;
    detail_user.string_content = string_question;
    detail_user.string_area = string_question_area;
    detail_user.string_time = string_time;
    detail_user.string_type = string_type;
    detail_user.string_caina = string_issolve;
    NSArray*array_img = [userinfo objectForKey:@"question_img"];
    if(!array_img || [array_img isKindOfClass:[NSNull class]]){
        
    }
    else{
        detail_user.array_img = array_img;
    }
    
    NSArray*array_img_small = [userinfo objectForKey:@"img_thumbnail"];
    if(!array_img_small || [array_img_small isKindOfClass:[NSNull class]]){
        
    }
    else{
        detail_user.array_img_small = array_img;
    }
    
    [array_data addObject:detail_user];
    
    //律师回复
    NSArray *array_lawyer = [dic objectForKey:@"questioninfo"];
    if(array_lawyer && [array_lawyer count] !=0){
        for (NSArray *array_ask in array_lawyer) {
            NSMutableArray *array_ask_reply = [NSMutableArray array];
            for(int i = 0; i<array_ask.count; i++){
                if(i == 0){
                    NSDictionary *dic_lawyer = array_ask[0];
                    NSString *string_diqu = [dic_lawyer objectForKey:@"area"];
                    NSString *string_dengji = [dic_lawyer objectForKey:@"class"];
                    NSString *string_neirong = [dic_lawyer objectForKey:@"content"];
                    NSString *string_lingyu = [dic_lawyer objectForKey:@"goodatfield"];
                    NSString *string_lvshiID = [dic_lawyer objectForKey:@"lawy_id"];
                    NSString *string_huifuID = [dic_lawyer objectForKey:@"lawyansw_id"];
                    NSString *string_gongzuoTime = [dic_lawyer objectForKey:@"life"];
                    NSString *string_zan = [dic_lawyer objectForKey:@"praise"];
                    NSString *string_wentiid = [dic_lawyer objectForKey:@"question_id"];
                    NSString *string_mingzi = [dic_lawyer objectForKey:@"realname"];
                    NSString *string_touxiang = [dic_lawyer objectForKey:@"head_src"];
                    NSString *string_time = [dic_lawyer objectForKey:@"time"];
                    NSNumber *string_caina = [dic_lawyer objectForKey:@"is_adopt"];
                    NSNumber *number_first = [dic_lawyer objectForKey:@"first"];
                    NSNumber *number_in_five = [dic_lawyer objectForKey:@"in_five"];
                    NSNumber *number_label = [dic_lawyer objectForKey:@"label"];
                    
                    if([string_lvshiID isEqual:string_uid]){
                        detail_user.string_myReplyId = string_huifuID;
                    }
                    
                    Model_lawyerReply *model_lawyer = [[Model_lawyerReply alloc] init];
                    model_lawyer.string_location = string_diqu;
                    model_lawyer.string_level = string_dengji;
                    model_lawyer.string_reContent = string_neirong;
                    model_lawyer.string_name = string_mingzi;
                    model_lawyer.string_time = string_time;
                    model_lawyer.string_year = string_gongzuoTime;
                    model_lawyer.string_questionID = string_wentiid;
                    model_lawyer.string_evaluateConut = string_zan;
                    model_lawyer.string_imagePath = string_touxiang;
                    model_lawyer.string_answerId = string_huifuID;
                    model_lawyer.string_id = string_lvshiID;
                    model_lawyer.int_kind = string_lingyu.integerValue;
                    model_lawyer.string_reState = [NSString stringWithFormat:@"%ld",(long)string_caina.integerValue];
                    model_lawyer.string_label = [NSString stringWithFormat:@"%ld",(long)number_label.integerValue];
                    model_lawyer.string_in_five = [NSString stringWithFormat:@"%ld",(long)number_in_five.integerValue];
                    model_lawyer.string_first = [NSString stringWithFormat:@"%ld",(long)number_first.integerValue];
                    [array_ask_reply addObject:model_lawyer];
                }
                else if(i%2 == 0){
                    Model_useAsked *model_ask = [[Model_useAsked alloc] init];
                    NSDictionary *dic_ask_user = array_ask[i];
                    NSString *string_ask_reply_id = [dic_ask_user objectForKey:@"question_id"];
                    NSString *string_question = [dic_ask_user objectForKey:@"content"];
                    NSString *string_time = [dic_ask_user objectForKey:@"time"];
                    model_ask.string_askID = string_ask_reply_id;
                    model_ask.string_content = string_question;
                    model_ask.string_time = string_time;
                    [array_ask_reply addObject:model_ask];
                }
                else{
                    Model_useAsked *model_ask = [[Model_useAsked alloc] init];
                    NSDictionary *dic_ask_user = array_ask[i];
                    NSString *string_ask_reply_id = [dic_ask_user objectForKey:@"id"];
                    //NSString *string_id = [dic_ask_user objectForKey:@"id"];
                    NSString *string_question = [dic_ask_user objectForKey:@"question"];
                    NSString *string_time = [dic_ask_user objectForKey:@"time"];
                    NSArray *array_img = [dic_ask_user objectForKey:@"question_img"];
                    if(!array_img || [array_img isKindOfClass:[NSNull class]]){
                        
                    }
                    else{
                        model_ask.array_img = array_img;
                    }
                    model_ask.string_askID = string_ask_reply_id;
                    model_ask.string_content = string_question;
                    model_ask.string_time = string_time;
                    [array_ask_reply addObject:model_ask];
                }
                
            }
            [array_data addObject:array_ask_reply];
        }
    }
    return array_data;
}

#pragma mark - 处理律师资料数据 -
/**
 *  处理律师资料数据
 */
+ (NSMutableArray *)deal_lawyerInfoWithDic:(NSDictionary *)dic{
    NSString *string_area = [dic objectForKey:@"area"];
    NSString *string_class = [dic objectForKey:@"class"];
    NSString *string_goodatfield = [dic objectForKey:@"goodatfield"];
    NSString *string_id = [dic objectForKey:@"id"];
    NSString *string_integral = [dic objectForKey:@"integral"];
    NSString *string_intro = [dic objectForKey:@"intro"];
    NSString *string_life = [dic objectForKey:@"life"];
    NSString *string_label = [dic objectForKey:@"label"];
    NSString *string_mechanism = [dic objectForKey:@"mechanism"];
    NSString *string_office_address = [dic objectForKey:@"office_address"];
    NSString *string_position = [dic objectForKey:@"position"];
    NSString *string_qualificati = [dic objectForKey:@"qualificati"];
    NSString *string_realname = [dic objectForKey:@"realname"];
    NSString *string_signatu = [dic objectForKey:@"signatu"];
    NSString *string_solvecount = [dic objectForKey:@"solvecount"];
    NSString *string_src = [dic objectForKey:@"head_src"];
    
    Model_lawyerInfo *info = [[Model_lawyerInfo alloc] init];
    if(string_id && ![string_id isKindOfClass:[NSNull class]]){
        info.string_lawyerID = string_id;
    }
    if(string_class && ![string_class isKindOfClass:[NSNull class]]){
        info.string_level = string_class;
    }
    if(string_life && ![string_life isKindOfClass:[NSNull class]]){
        info.string_life = string_life;
    }
    if(string_goodatfield && ![string_goodatfield isKindOfClass:[NSNull class]]){
        info.string_kind = string_goodatfield;
    }
    if(string_area && ![string_area isKindOfClass:[NSNull class]]){
        info.string_lawyerArea = string_area;
    }
    if(string_integral && ![string_integral isKindOfClass:[NSNull class]]){
        info.string_integral = string_integral;
    }
    if(string_intro && ![string_intro isKindOfClass:[NSNull class]]){
        info.string_intro = string_intro;
    }
    if(string_mechanism && ![string_mechanism isKindOfClass:[NSNull class]]){
        info.string_mechanism = string_mechanism;
    }
    if(string_office_address && ![string_office_address isKindOfClass:[NSNull class]]){
        info.string_officeAddress = string_office_address;
    }
    if(string_position && ![string_position isKindOfClass:[NSNull class]]){
        info.string_position = string_position;
    }
    if(string_qualificati && ![string_qualificati isKindOfClass:[NSNull class]]){
         info.string_qualificati = string_qualificati;
    }
    if(string_realname && ![string_realname isKindOfClass:[NSNull class]]){
        info.string_realname = string_realname;
    }
    if(string_signatu && ![string_signatu isKindOfClass:[NSNull class]]){
        info.string_signatu = string_signatu;
    }
    if(string_solvecount && ![string_solvecount isKindOfClass:[NSNull class]]){
        info.string_solvecount = string_solvecount;
    }
    if(string_src && ![string_src isKindOfClass:[NSNull class]]){
        info.string_portrait = string_src;
    }
    if(string_label && ![string_label isKindOfClass:[NSNull class]]){
        info.string_title = string_label;
    }
    NSMutableArray *array_data = [NSMutableArray arrayWithObject:info];
    return array_data;
}

#pragma mark - 处理我的评论数据 -
/**
 *  处理我的评论数据
 */
+ (NSMutableArray *)deal_myComment:(NSDictionary *)dic{
    NSString *string_area = [dic objectForKey:@"question_area"];
    NSString *string_class = [dic objectForKey:@"class"];
    NSString *string_goodatfield = [dic objectForKey:@"question_type"];
    NSString *string_id = [dic objectForKey:@"lawy_id"];
    NSString *string_content = [dic objectForKey:@"content"];
    NSString *string_fuwu_fraction = [dic objectForKey:@"fuwu_fraction"];
    NSString *string_life = [dic objectForKey:@"life"];
    NSString *string_label = [dic objectForKey:@"label"];
    //NSString *string_realname = [dic objectForKey:@"mobile"];
    NSString *string_xy_fraction = [dic objectForKey:@"xy_fraction"];
    NSString *string_ziliang_fraction= [dic objectForKey:@"ziliang_fraction"];
    //NSString *string_src = [dic objectForKey:@"src"];
    
    Model_myComment *myComment = [[Model_myComment alloc] init];
    myComment.string_title = string_label;
    myComment.string_id = string_id;
    myComment.string_area = string_area;
    myComment.string_class = string_class;
    myComment.string_goodatfield = string_goodatfield;
    if(!string_content || [string_content isKindOfClass:[NSNull class]]){
        myComment.string_content = @"";
    }
    else{
        myComment.string_content = string_content;
    }
    if(!string_fuwu_fraction || [string_fuwu_fraction isKindOfClass:[NSNull class]]){
        myComment.string_fuwu_fraction = @"0";
    }
    else{
        myComment.string_fuwu_fraction = string_fuwu_fraction;
    }
    if(!string_xy_fraction || [string_xy_fraction isKindOfClass:[NSNull class]]){
        myComment.string_xy_fraction = @"0";
    }
    else{
        myComment.string_xy_fraction = string_xy_fraction;
    }
    if(!string_ziliang_fraction || [string_ziliang_fraction isKindOfClass:[NSNull class]]){
        myComment.string_ziliang_fraction = @"0";
    }
    else{
        myComment.string_ziliang_fraction = string_ziliang_fraction;
    }
    
    myComment.string_life = string_life;
    //myComment.string_realname = string_realname;
    //myComment.string_src = string_src;
    
    NSMutableArray *array_data = [NSMutableArray arrayWithObject:myComment];
    return array_data;
}

#pragma mark - 处理我的回答列表 -
/**
 *  处理我的回答列表
 */
+ (NSMutableArray *)deal_myListDataWithDicArray:(NSArray *)array_dic{
    NSMutableArray *array_data = [NSMutableArray arrayWithCapacity:[array_dic count]];
    for(NSDictionary *dic in array_dic){
        NSString *string_id = [dic objectForKey:@"id"];
        NSString *string_count = [dic objectForKey:@"answcount"];
        NSString *string_text = [dic objectForKey:@"question"];
        NSString *string_time = [dic objectForKey:@"time"];
        NSString *string_is_solve = [dic objectForKey:@"is_solve"];
        NSString *string_lawyunread = [dic objectForKey:@"lawyunread"];
        
        Model_myList *model_list = [[Model_myList alloc] init];
        if(string_id && ![string_id isKindOfClass:[NSNull class]]){
            model_list.string_id = string_id;
        }
        if(string_count && ![string_count isKindOfClass:[NSNull class]]){
            model_list.string_count = string_count;
        }
        if(string_text && ![string_text isKindOfClass:[NSNull class]]){
            model_list.string_content = string_text;
        }
        if(string_time && ![string_time isKindOfClass:[NSNull class]]){
            model_list.string_time = string_time;
        }
        if(string_is_solve && ![string_is_solve isKindOfClass:[NSNull class]]){
            model_list.string_isSolve = string_is_solve;
        }
        if(string_lawyunread && ![string_lawyunread isKindOfClass:[NSNull class]]){
            model_list.string_unRead = string_lawyunread;
        }
        [array_data addObject:model_list];
    }
    return array_data;
}

@end
